#include <bits/stdc++.h>
using namespace std;
const int len = 32;
bool pic[len][len];
string s1, s2;
int n;

void solve(int r, int c, int w, string s){
    char cmd = s[n++];
    if(cmd == 'p'){
        solve(r, c+w/2, w/2, s);
        solve(r, c, w/2, s);
        solve(r+w/2, c, w/2, s);
        solve(r+w/2, c+w/2, w/2, s);
    }
    else if(cmd == 'f'){
        for (int i = r; i < r+w; ++i) {
            for (int j = c; j < c+w; ++j) {
                pic[i][j] = true;
            }
        }
    }
}

int main() {
    //ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T; cin >> T; cin.get();
    while(T--) {
        memset(pic, false, sizeof(pic));
        getline(cin, s1); getline(cin, s2);
        n = 0; solve(0, 0, len,  s1);
        n = 0; solve(0, 0, len,  s2);

        int ans = 0;
        for (int r = 0; r < len; ++r) {
            for (int c = 0; c < len; ++c) {
                if(pic[r][c]) ++ans;
            }
        }

        cout << "There are " << ans << " black pixels.\n";
        //if(T)cout << "\n";
    }
    return 0;
}